
const char * vertexShaderCode =
        "#version 330 core\r\n"
        "layout (location = 0) in vec3 aPos;"
        "layout (location = 1) in vec3 aNormal;"
        "layout (location = 2) in vec2 aTexCoord;"
        ""
        "out vec3 FragPos;"
        "out vec3 Normal;"
        "out vec2 TexCoord;"
        ""
        "uniform mat4 model;"
        "uniform mat4 view;"
        "uniform mat4 projection;"
        ""
        "void main()"
        "{"
        "    FragPos = vec3(model * vec4(aPos, 1.0));"
        "    Normal = mat3(transpose(inverse(model))) * aNormal;"
        "    TexCoord = vec2(aTexCoord.x, aTexCoord.y);"
        "    gl_Position = projection * view * vec4(FragPos, 1.0);"
        "}";

const char * fragmentShaderCode =
        "#version 330 core\r\n"
        ""
        "out vec4 FragColor;"
        "in vec3 FragPos;"
        "in vec3 Normal;"
        "in vec2 TexCoord;"
        ""
        "struct Material {"
        "    sampler2D texture_diffuse;"
        "    vec3 ambient;"
        "    vec3 diffuse;"
        "    vec3 specular;"
        "    float shininess;"
        "};"
        "struct Light {"
        "    vec3 position;"
        "    vec3 direction;"
        "    float cutOff;"
        "    float outerCutOff;"
        "    vec3 ambient;"
        "    vec3 diffuse;"
        "    vec3 specular;"
        "    float constant;"
        "    float linear;"
        "    float quadratic;"
        "};"
        "uniform int texType;"
        "uniform int texNum;"
        "uniform vec3 orgColor;"
        "uniform sampler2D texture1;"
        "uniform sampler2D texture2;"
        "uniform vec3 viewPos;"
        "uniform Material material;"
        "uniform Light light;"
        ""
        "void main()"
        "{"
        "    vec4 mixture = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.5);"
        ""
        "    if (texType == 0) {"
        "        FragColor = vec4(orgColor, 1.0);"
        "    } else if (texType == 1) {"
        "        FragColor = texture(texture1, TexCoord);"
        "    } else if (texType == 2) {"
        "        FragColor = texture(texture2, TexCoord);"
        "    } else if (texType == 3) {"
        "        FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.5);"
        "    } else if (texType == 4) {"
        ""
        "        vec3 ambient = light.ambient * material.ambient;"
        "        if (texNum != 0) ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) ambient = light.ambient * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 norm = normalize(Normal);"
        "        vec3 lightDir = normalize(light.position - FragPos);"
        "        float diff = max(dot(norm, lightDir), 0.0);"
        "        vec3 diffuse = light.diffuse * diff * material.diffuse;"
        "        if (texNum != 0) diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) diffuse = light.diffuse * diff * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 viewDir = normalize(viewPos - FragPos);"
        "        vec3 reflectDir = reflect(-lightDir, norm);"
        "        float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);"
        "        vec3 specular = light.specular * spec * material.specular;"
        ""
        "        float distance    = length(light.position - FragPos);"
        "        float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));"
        "        ambient  *= attenuation;"
        "        diffuse   *= attenuation;"
        "        specular *= attenuation;"
        ""
        "        vec3 result = ambient + diffuse + specular;"
        "        FragColor = vec4(result, 1.0);"
        "    } else if (texType == 5) {"
        ""
        "        vec3 ambient = light.ambient * material.ambient;"
        "        if (texNum != 0) ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) ambient = light.ambient * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 norm = normalize(Normal);"
        "        vec3 lightDir = normalize(-light.direction);"
        "        float diff = max(dot(norm, lightDir), 0.0);"
        "        vec3 diffuse = light.diffuse * diff * material.diffuse;"
        "        if (texNum != 0) diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) diffuse = light.diffuse * diff * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 viewDir = normalize(viewPos - FragPos);"
        "        vec3 reflectDir = reflect(-lightDir, norm);"
        "        float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);"
        "        vec3 specular = light.specular * spec * material.specular;"
        ""
        "        vec3 result = ambient + diffuse + specular;"
        "        FragColor = vec4(result, 1.0);"
        "    } else if (texType == 6) {"
        ""
        "        vec3 ambient = light.ambient * material.ambient;"
        "        if (texNum != 0) ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) ambient = light.ambient * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 norm = normalize(Normal);"
        "        vec3 lightDir = normalize(light.position - FragPos);"
        "        float diff = max(dot(norm, lightDir), 0.0);"
        "        vec3 diffuse = light.diffuse * diff * material.diffuse;"
        "        if (texNum != 0) diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));"
        "        if (texNum == 3) diffuse = light.diffuse * diff * vec3(mixture.x, mixture.y, mixture.z);"
        ""
        "        vec3 viewDir = normalize(viewPos - FragPos);"
        "        vec3 reflectDir = reflect(-lightDir, norm);"
        "        float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);"
        "        vec3 specular = light.specular * spec * material.specular;"
        ""
        "        float theta = dot(lightDir, normalize(-light.direction)); "
        "        float epsilon = (light.cutOff - light.outerCutOff);"
        "        float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);"
        "        diffuse  *= intensity;"
        "        specular *= intensity;"
        ""
        "        float distance    = length(light.position - FragPos);"
        "        float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));"
        "        ambient  *= attenuation;"
        "        diffuse   *= attenuation;"
        "        specular *= attenuation;"
        ""
        "        vec3 result = ambient + diffuse + specular;"
        "        FragColor = vec4(result, 1.0);"
        "    }"
        "}";


const char * lampVertexShaderCode =
        "#version 330 core\r\n"
        "layout (location = 0) in vec3 aPos;"
        ""
        "uniform mat4 model;"
        "uniform mat4 view;"
        "uniform mat4 projection;"
        ""
        "void main()"
        "{"
        "    gl_Position = projection * view * model * vec4(aPos, 1.0);"
        "}";

const char * lampFragmentShaderCode =
        "#version 330 core\r\n"
        "out vec4 FragColor;"
        ""
        "void main()"
        "{"
        "    FragColor = vec4(1.0);"
        "}";

//const char* vertexShaderCodeNew =
//        "#version 330 core\r\n"
//        "layout (location = 0) in vec3 aPos;"
//        "layout (location = 1) in vec3 aCol;"
//        ""
//        "out vec3 daColor;"
//        ""
//        "uniform mat4 model;"
//        "uniform mat4 view;"
//        "uniform mat4 projection;"
//        ""
//        "void main()"
//        "{"
//        "    gl_Position = projection * view * model * vec4(aPos, 1.0f);"
//        "    daColor = aCol;"
//        "}";

//const char* fragmentShaderCodeNew =
//        "#version 330 core\r\n"
//        ""
//        "out vec4 FragColor;"
//        "in vec3 daColor;"
//        ""
//        "void main()"
//        "{"
//        "    FragColor = vec4(daColor, 1.0);"
//        "}";

